import { getJwt } from "@/api/jwt.js"

// 移动端页面导入
import MobileLogin from '@/components/mobile/LoginMobile.vue'
import MobileHome from '@/components/mobile/MoibleMain.vue'
import MobileReg from '@/components/mobile/RegistryMobile.vue'

// 移动端路由配置
const mobileRoutes = [
    {
        name: "移动端首页",
        path: "/main",
        component: MobileHome,
        meta: {
            isMobile: true,
            requiresAuth: true,
            title: "首页"
        }
    },
    // {
    //     name: "移动端用户管理",
    //     path: "/user",
    //     component: MobileUser,
    //     meta: {
    //         isMobile: true,
    //         requiresAuth: true,
    //         title: "用户管理"
    //     }
    // },
    // {
    //     name: "移动端宠物管理",
    //     path: "/pet",
    //     component: MobilePet,
    //     meta: {
    //         isMobile: true,
    //         requiresAuth: true,
    //         title: "宠物管理"
    //     }
    // },
    {
        name: "移动端登录页",
        path: "/login",
        component: MobileLogin,
        meta: {
            isMobile: true,
            requiresAuth: false,
            title: "登录"
        }
    },{
        name:"移动端注册页",
        path: "/registry",
        component: MobileReg,
    },
    {
        name: "移动端根路径",
        path: "/",
        redirect: "/main"
    }
]

// 移动端路由守卫
export const mobileBeforeEach = (to, from, next) => {
    const jwt = getJwt()
    const requiresAuth = to.meta.requiresAuth

    if (requiresAuth && !jwt) {
        // 需要登录但未登录，跳转到登录页
        next('/login')
    } else if (!requiresAuth && jwt && to.path === '/login') {
        // 已登录但访问登录页，跳转到首页
        next('/main')
    } else {
        // 其他情况正常放行
        next()
    }
}

// 设备检测函数
export const isMobileDevice = () => {
    return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
}

export default mobileRoutes